﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.Extensions.Configuration.Json;

namespace Infrastructure.Lib.Core
{
    public class EncryptedJsonConfigurationProvider : JsonConfigurationProvider
    {
        public EncryptedJsonConfigurationProvider(EncryptedJsonConfigurationSource source) : base(source)
        {
        }

        public override void Load(Stream stream)
        {
            StreamReader reader = new StreamReader(stream);
            string sourceText = reader.ReadToEnd();
            var decryptedText = DesHelper.Decrypt(sourceText, "Strong9889gnorts1234%^&*");

            byte[] array = Encoding.UTF8.GetBytes(decryptedText);
            stream = new MemoryStream(array);
            
            base.Load(stream);

            // 读取配置文件需要的节点数据，然后解密
            // 请自已实现加密和解密的方法，这里未提供加密/解密的实现

            //Data["abc:password"] = MyEncryptionLibrary.Decrypt(Data["abc:password"]);
        }
    }
}
